#!/bin/bash

if [[ $# -ne 2 ]]; then
    echo "The format is as follows:"
    echo "bash sip-4.18.sh buildpath installpath"
    echo ":param buildpath: 应用构建绝对路径"
    echo ":param installpath: 应用安装绝对路径"
    exit 1
fi

if [[ ! "$1" =~ ^/.* || ! -d "$1" || "$1" = "/" ]]; then
    echo "请输入正确的构建路径"
    exit 1
fi
if [[ ! "$2" =~ ^/.* || ! -d "$2" || "$2" = "/" ]]; then
    echo "请输入正确的安装路径"
    exit 1
fi

buildpath=$1
installpath=$2
if [[ "$1" =~ .*/$ ]]; then buildpath=${buildpath%/*}; fi
if [[ "$2" =~ .*/$ ]]; then installpath=${installpath%/*}; fi
[[ "$buildpath" == "$installpath" ]] && echo "构建路径与安装路径需为不同路径" && exit 1
set -e
yum install qt5-qtquickcontrols qt5-qtdeclarative-devel qt5-qtbase-devel -y
yum install python-devel python3-devel -y
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple h5py
wget -t 40 -c -P $buildpath http://nchc.dl.sourceforge.net/project/pyqt/sip/sip-4.18/sip-4.18.tar.gz
tar -xzvf $buildpath/sip-4.18.tar.gz -C $buildpath && rm -rf $buildpath/sip-4.18.tar.gz
cd $buildpath/sip-4.18
python3 configure.py CC=clang CXX=clang++
make && make install
rm -rf $buildpath/sip-4.18
rm -rf $buildpath/itk_bin